﻿Imports DTO
Public Class ThucDonDAO
    Public Function LoadListThucDonDAO() As List(Of ThucDonDTO)
        Dim sql As String = "Select * from ThucDon where TinhTrang > 0"

        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)

        Dim _listThucDon As New List(Of ThucDonDTO)

        For Each row As DataRow In dt.Rows
            Dim _maMenu As Integer = Integer.Parse(row(0).ToString())
            Dim _donGia As Double = Double.Parse(row(1).ToString())
            Dim _ten As String = row(2).ToString()
            Dim _tinhTrang As Integer = row(3).ToString()
            Dim _thucDonDTO As New ThucDonDTO(_maMenu, _donGia, _ten, _tinhTrang)
            _listThucDon.Add(_thucDonDTO)
        Next
        Return _listThucDon
    End Function

    Public Function LayThongTinThucDonDAO(ByVal _maMenu As Integer) As ThucDonDTO
        Dim sql = "Select * from ThucDon where MaMenu = " & _maMenu
        Dim dt As New DataTable()
        dt = DataProvider.LoadSQL(sql)
        '_iMaMenu = New Integer()
        '_dDonGia = New Double()
        '_sTen = New String()
        '_sTinhTrang = New Integer()

        Dim MaMenu As Integer = Integer.Parse(dt.Rows(0)("MaMenu").ToString())
        Dim DonGia As Double = Double.Parse(dt.Rows(0)("DonGia").ToString())
        Dim Ten As String = dt.Rows(0)("Ten").ToString()
        Dim TinhTrang As Integer = Integer.Parse(dt.Rows(0)("TinhTrang").ToString())
        Dim _thucDonDTO As New ThucDonDTO(MaMenu, DonGia, Ten, TinhTrang)
        Return _thucDonDTO
    End Function
    Public Function LoadThucDon() As DataTable
        Dim sql As String = "select * from ThucDon"
        Dim dt As DataTable
        dt = DataProvider.LoadSQL(sql)
        Return dt
    End Function

    Public Sub AddTD(ByVal _td As DTO.ThucDonDTO)
        Dim sql As String
        sql = String.Format("insert into ThucDon values ({0},N'{1}',{2})", _td.DonGia, _td.Ten, _td.TinhTrang)
        DataProvider.ExcuteQuery(sql)
    End Sub
    Public Sub UpdateTD(ByVal _td As DTO.ThucDonDTO)
        Dim sql As String
        sql = String.Format("update ThucDon set Ten = N'{0}' , DonGia = {1} , TinhTrang = {2}  where MaMenu = {3}", _td.Ten, _td.DonGia, _td.TinhTrang, _td.MaMenu)
        DataProvider.ExcuteQuery(sql)
    End Sub
    Public Sub DelTD(ByVal _td As DTO.ThucDonDTO)
        Dim sql As String
        sql = "update ThucDon set TinhTrang = 3 where MaMenu = " + _td.MaMenu.ToString()
        DataProvider.ExcuteQuery(sql)
    End Sub
End Class
